home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’95
/
Search Example
/
TTY_Messages.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-23
|
4KB
|
191 lines
/** FILE: TTY_Messages.c **/
/** Manage scrolling message area **/
#define DEBUG 0 /*turn on for main program*/
#define MPW_C 0 /*turn off for lightspeed*/
#include <stdio.h>
#include <string.h>
#include <GestaltEqu.h>
#include <AppleEvents.h>
#include <Types.h>
#include <Memory.h>
#include <Windows.h>
#include <Dialogs.h>
#include <Menus.h>
#include <Fonts.h>
#include <Events.h>
#include <OSEvents.h>
#include <Desk.h>
#include <ToolUtils.h>
#include "TTY_Messages.h"
int MSG_FONT = monaco;
int MSG_FONT_SIZE = 9;
#define MSG_SIZE 1024 /*** Increase for larger messages ***/
Rect msgBounds;
Rect topBounds;
int lineIndex;
char topLine[100];
#define maxTElines 100 /*Max lines in TErec before deletion*/
#define minTElines 40 /*Number of lines in TErec after deletion*/
#define maxint 32767
TEHandle msgEdit; /*TErec for one and only message area*/
WindowPtr ttyWin; /*Window containing the message area*/
Rect destRect; /*Destination Rect for TE stuff*/
Rect viewRect; /*TE view rectangle */
int fontNum; /*Font number of Venice 12 */
/****************************/
TTY_Die()
{
ExitToShell();
}
/****************************/
void TTY_InitMessages(WindowPtr theWin, Rect r, int font, int font_size)
/* Init for programs with windows already */
{
/* SetRect(&msgBounds,MSG_LEFT, MSG_TOP, MSG_LEFT+MSG_X_DIM, MSG_TOP+MSG_Y_DIM);*/
SetRect(&msgBounds,r.left,r.top,r.right,r.bottom);
lineIndex = 0;
/**/
MSG_FONT = font;
MSG_FONT_SIZE = font_size;
ttyWin = theWin;
destRect = msgBounds;
SetPort(ttyWin);
viewRect = destRect;
InsetRect(&viewRect,0,4);
InsetRect(&destRect,4,4);
TextFont(MSG_FONT);
TextSize(MSG_FONT_SIZE);
msgEdit = TENew(&destRect, &viewRect);
(**msgEdit).crOnly = 1;
TESetJust(0, msgEdit);
TEAutoView(1, msgEdit);
}
/****************************/
void TTY_SAInitMessages()
/** Initialization for stand-alone, dumb tty applications. **/
/** Should be the FIRST call in your main program. **/
{
Rect r;
MaxApplZone();
MoreMasters();
#if MPW_C
InitGraf(&qd.thePort);
#else
InitGraf(&thePort);
#endif
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(TTY_Die);
InitCursor();
SetRect(&r,5,40,512,460);
ttyWin = NewWindow(NULL, &r, "\pDebug", 1, 0, (Ptr) -1, 0, 0);
OffsetRect(&r,0,-40);
InsetRect(&r,2,2);
TTY_InitMessages(ttyWin, r, MSG_FONT, MSG_FONT_SIZE);
}
/*********************/
void TTY_RedrawMessages()
/*repaint the message area*/
{
Rect r;
SetPort(ttyWin);
r=msgBounds;
InsetRect(&r,0,-1);
EraseRect(&r);
InsetRect(&r,-1,-1);
FrameRect(&r);
(**msgEdit).txFont = MSG_FONT;
/**/ TEUpdate(&viewRect, msgEdit);/**/
}
/*********************/
void TTY_WriteMessage(char *str)
/** writes a message to the debug window, adding a CR at the end **/
{
EventRecord event;
int startPos;
char msg[MSG_SIZE];
SetPort(ttyWin);
TESetSelect(maxint, maxint, msgEdit);
#if MPW_C
sprintf(msg,"%s\n",str);
#else
sprintf(msg,"%s\r",str);
#endif
TEInsert(msg, strlen(msg), msgEdit);
startPos = (**msgEdit).lineStarts[(**msgEdit).nLines] - 1;
TESetSelect(startPos, startPos, msgEdit);
if ((**msgEdit).nLines >= maxTElines)
{
TESetSelect(0, (**msgEdit).lineStarts[maxTElines-minTElines]-1, msgEdit);
TEDelete(msgEdit);
startPos = (**msgEdit).lineStarts[(**msgEdit).nLines] - 1;
TESetSelect(startPos, startPos, msgEdit);
}/**/
TESelView(msgEdit);
if (EventAvail(everyEvent,&event));
}
/**********************/
void TTY_ClearMessages()
/** clear out top line and message area*/
{
TESetSelect(0, 32767, msgEdit);
TEDelete(msgEdit);
}
/**********************/
void TTY_Click()
/*wait for a mouse click*/
{
EventRecord event;
while (!Button())
if (EventAvail(everyEvent,&event));
while (Button());
}
#if DEBUG
main()
{
char s[80];
int i,j;
TTY_SAInitMessages();
for (j=0;j<5;j++) {
for (i=0;i<10;i++) {
sprintf(s,"Line %d",i);
TTY_WriteMessage(s);
}
TTY_Click();
}
}
#endif